import 'package:catguard/language.dart';
import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../config/config.dart';
import '../../generated/assets.dart';
import '../../views/common_widget.dart';
import 'msg_center_logic.dart';

class MsgCenterPage extends StatelessWidget {
  MsgCenterPage({super.key});

  final logic = Get.find<MsgCenterLogic>();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Config.colorBg,
      resizeToAvoidBottomInset: false,
      body: Stack(
        children: [
          Column(
            children: [
              CommonWidget.commonAppBar(LanguageMsg.mineMsgCenter.tr),
              SizedBox(
                height: 0.w,
              ),
              Expanded(
                child: EasyRefresh.builder(
                  controller: logic.refreshController,
                  onRefresh: () {
                    logic.page = 1;
                    logic.loadData();
                  },
                  onLoad: () {
                    logic.loadData();
                  },
                  childBuilder: (context, scrollPhysics) {
                    return Obx(
                      () => logic.listData.isEmpty
                          ? CommonWidget.showNullData()
                          : ListView.builder(
                              itemCount: logic.listData.length,
                              padding: EdgeInsets.only(top: 30.w, left: 0, right: 0.w),
                              physics: scrollPhysics,
                              itemBuilder: (BuildContext context, int index) {
                                return getItem(index);
                              },
                            ),
                    );
                  },
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }

  getItem(int index) {
    return GestureDetector(
      onTap: () {},
      child: Container(
        padding: EdgeInsets.symmetric(horizontal: 26.w, vertical: 24.w),
        margin: EdgeInsets.only(bottom: 24.w, left: 34.w, right: 34.w),
        decoration: BoxDecoration(
          color: Config.colorBg2,
          borderRadius: BorderRadius.circular(Config.roundNormal.w),
        ),
        child: Column(
          children: [
            //图标，标题，时间
            Row(
              children: [
                Container(
                  width: 50.w,
                  height: 50.w,
                  padding: EdgeInsets.all(10.w),
                  decoration: BoxDecoration(
                      color: Config.colorMain.withOpacity(0.3),
                      borderRadius: BorderRadius.circular(26.w)),
                  child: Image.asset(Assets.imagesProduct01Mini),
                ),
                SizedBox(width: 15.w),
                Text(
                  "设备消息",
                  style: TextStyle(color: Config.colorText1, fontSize: Config.textSizeContent.sp),
                ),
                Expanded(
                  child: Container(
                    alignment: Alignment.centerRight,
                    child: Text(
                      "15:32",
                      style:
                          TextStyle(color: Config.colorText3, fontSize: Config.textSizeInfo.sp),
                    ),
                  ),
                ),
              ],
            ),
            //分割线
            SizedBox(height: 20.w),
            CommonWidget.commonDivider(),
            SizedBox(height: 20.w),
            //消息正文
            Container(
              alignment: Alignment.centerLeft,
              child: Text(
                "CatGuard提醒你来清空集便箱啦~",
                style: TextStyle(color: Config.colorText1, fontSize: Config.textSizeContent.sp),
              ),
            ),
            SizedBox(height: 10.w),
            Container(
              alignment: Alignment.centerLeft,
              child: Text(
                "记得去处理，勤扔粑粑为猫咪提供健康干净的入厕环境~\n下次提醒时间为04-12 09:00",
                style: TextStyle(color: Config.colorText3, fontSize: Config.textSizeInfo.sp,height: 1.4),
              ),
            ),
            //分割线
            SizedBox(height: 20.w),
            CommonWidget.commonDivider(),
            SizedBox(height: 20.w),
            //底部
            Row(
              children: [
                Text(
                  "五八万的厕所",
                  style: TextStyle(color: Config.colorText3, fontSize: Config.textSizeInfo.sp),
                ),
                Expanded(
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.end,
                    children: [
                      Text(
                        "来源家庭：",
                        style:
                        TextStyle(color: Config.colorText3, fontSize: Config.textSizeMinor.sp),
                      ),
                      Text(
                        "Sam的家",
                        style:
                        TextStyle(color: Config.colorText3, fontSize: Config.textSizeMinor.sp),
                      )
                    ],
                  ),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
